package com.wb.mas.widget;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.view.Display;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebView;
import android.widget.CheckBox;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.wb.mas.R;

import me.goldze.mvvmhabit.utils.ToastUtils;

/**
 * Copyright (C) 2018,
 * PrivacyDialog
 * <p>
 * Description
 *
 * @author yue
 * @version 1.0
 * <p>
 * Ver 1.0, 2019-05-22, yue, Create file
 */
public class PrivacyDialog extends Dialog {

    private View rootView;
    private Context mContext;
    private CheckBox mCb;
    private TextView mTvText;
    private WebView webview;
    private TextView mTvTolak;
    private OnPricyClickLister onPricyClickLister;

    public PrivacyDialog(@NonNull Context context) {
        super(context, R.style.privacy_dialog);
        mContext = context;
        initView();
    }

    public void setOnPricyClickLister(OnPricyClickLister onPricyClickLister) {
        this.onPricyClickLister = onPricyClickLister;
    }

    private void initView() {
        rootView = View.inflate(mContext, R.layout.dig_privacy, null);
        mCb = rootView.findViewById(R.id.cb_select);
        mTvText = rootView.findViewById(R.id.tv_text);
        webview = rootView.findViewById(R.id.webview);
        mTvTolak = rootView.findViewById(R.id.tv_tolak);


        mTvTolak.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mCb.isChecked()) {
                    onPricyClickLister.onTolakClick();
                    dismiss();
                } else {
                    ToastUtils.showShort("Harap baca dan setujui perjanjian privasi");
                }
            }
        });
        Display display = ((Activity) mContext).getWindowManager().getDefaultDisplay();
        int width = display.getWidth();
        int height = display.getHeight();
        ViewGroup.LayoutParams layoutParams = new ViewGroup.LayoutParams(width, height);
        setContentView(rootView, layoutParams);
        webview.loadUrl("https://heresds.linktekxn.com/privacy.html");
      }

    public interface OnPricyClickLister {
        void onTolakClick();
    }


}
